﻿
#include "lv_common_function.h"

 

lv_obj_t* prj_parent_cont;
lv_obj_t* prj_prev_cont;
lv_obj_t* prj_float_cont = NULL;
lv_obj_t* prj_call_cont = NULL;
lv_group_t* prj_group;
uint8_t dsp_ipc_cmd;
lv_font_t bin_font;
lv_point_t sys_scroll_sum;

extern uint8_t key_code;
extern bool coming_call_ok;

//frame 2:

void ui_main_float(lv_obj_t* parent);
void lv_main_cont(lv_obj_t* obj);
void lv_float_cont(lv_obj_t* obj);
void lv_guimain(lv_obj_t* obj);
static void main_cont_cb(lv_event_t* e);
static void float_cont_cb(lv_event_t* e);

extern void main_ui0_entry(lv_obj_t* obj);



//#define		LV_HOR_RES_MAX		240
//#define		LV_VER_RES_MAX		280



pri_ui_entry pri_ui_group[] =
{

    ui_main_float,
    //lv_app_starsky_btn,


};



static void event_handler(lv_event_t* e)
{
    lv_event_code_t event = lv_event_get_code(e);

}




void lv_prj_main(void)
{

    //	lv_init_bin_font(FONT_BIN_ARIALUNI_20,*(font_addr + 1),&arialuni_20);

   // memset(&ui_info, 0, sizeof(ui_info_t));



    prj_parent_cont = lv_obj_create(lv_scr_act());
    lv_obj_set_style_pad_all(prj_parent_cont, 0, 0);
    lv_obj_set_style_border_width(prj_parent_cont, 0, 0);
    lv_obj_set_size(prj_parent_cont, LV_PCT(100), LV_PCT(100));
    lv_obj_add_flag(prj_parent_cont, LV_OBJ_FLAG_SCROLL_ONE);
    lv_obj_set_scroll_snap_x(prj_parent_cont, LV_SCROLL_SNAP_CENTER);
    lv_obj_set_scroll_snap_y(prj_parent_cont, LV_SCROLL_SNAP_CENTER);
    lv_obj_set_scrollbar_mode(prj_parent_cont, LV_SCROLLBAR_MODE_OFF);
    lv_obj_clear_flag(prj_parent_cont, LV_OBJ_FLAG_SCROLL_ELASTIC);
    lv_obj_add_event_cb(prj_parent_cont, event_handler, LV_EVENT_ALL, NULL);

    //
    prj_group = lv_group_create();
    //lv_indev_set_group(indev_keypad, prj_group);
    //lv_group_add_obj(prj_group, prj_parent_cont);

    prj_prev_cont = lv_obj_create(prj_parent_cont);



    //printf("sync_cm3_data.ui_info.ui_mode %d \n", sync_cm3_data.ui_info.ui_mode);


    //pri_ui_group[sync_cm3_data.ui_info.ui_mode](prj_prev_cont);


    //dsp_store_ui_scene(0,1,0,0,0);
    ui_main_float(prj_prev_cont);




}

/*=====================================================================
    frame 2:
======================================================================*/
static void ui_main_timer_cb(lv_timer_t* t)
{
    lv_obj_t* obj = t->user_data;

    lv_timer_del(t);

    if (!lv_obj_is_valid(obj))
        return;

    lv_obj_t* main_float_cont = lv_obj_create(obj);
    lv_float_cont(main_float_cont);


}

//lv_frame2_main();
void ui_main_float(lv_obj_t* parent)
{
    if (!lv_obj_is_valid(parent))
        return;

    //init parent obj
    lv_obj_set_style_pad_all(parent, 0, 0);
    lv_obj_set_style_border_width(parent, 0, 0);
    lv_obj_set_size(parent, LV_PCT(100), LV_PCT(100));
    lv_obj_add_flag(parent, LV_OBJ_FLAG_SCROLL_ONE);
    lv_obj_set_scroll_snap_x(parent, LV_SCROLL_SNAP_CENTER);
    lv_obj_set_scroll_snap_y(parent, LV_SCROLL_SNAP_CENTER);
    lv_obj_set_scrollbar_mode(parent, LV_SCROLLBAR_MODE_OFF);
    lv_obj_clear_flag(parent, LV_OBJ_FLAG_SCROLL_ELASTIC);

    lv_obj_t* main_cont = lv_obj_create(parent);
    lv_float_cont(main_cont);
#if 0
    lv_main_cont(main_cont);

    if ((dsp_get_ui_scene_page_by_layer(1)) == 0)
    {
        lv_timer_create(ui_main_timer_cb, 50, parent);
    }
    else
    {
        lv_obj_t* main_float_cont = lv_obj_create(parent);
        lv_float_cont(main_float_cont);
        if ((dsp_get_ui_scene_page_by_layer(1)) >= 4)
        {
            lv_obj_move_foreground(main_cont);
            lv_obj_scroll_by(main_cont, -(dsp_get_ui_scene_page_by_layer(1) - 4) * LV_HOR_RES_MAX, 0, LV_ANIM_OFF);
        }
    }
#endif

}

static void main_cont_cb(lv_event_t* e) //lv_main_cont 滚动回调事件
{

    lv_event_code_t code = lv_event_get_code(e);
    lv_obj_t* obj = lv_event_get_target(e);
    if (!lv_obj_is_valid(obj))
        return;

    lv_obj_t* kb = lv_event_get_user_data(e);
    if (!lv_obj_is_valid(kb))
        return;

    if (code == LV_EVENT_SCROLL_END)
    {
        lv_coord_t temp = lv_obj_get_scroll_left(kb);//从左侧获取滚动坐标
        //printf("LV_EVENT_SCROLL_END\n");

        if (temp == 0)//到达最左侧的界面了 
        {
            //dsp_store_ui_scene(0, 1, 0, 0, 0);
            lv_obj_add_flag(lv_obj_get_parent(obj), LV_OBJ_FLAG_SCROLLABLE);
            lv_obj_add_flag(lv_obj_get_parent(lv_obj_get_parent(obj)), LV_OBJ_FLAG_SCROLLABLE);
            printf("page 0 \n");
        }
        else
        {
            //dsp_store_ui_scene(0, 1, (4 + temp / LV_HOR_RES_MAX), 0, 0);
            lv_obj_clear_flag(lv_obj_get_parent(obj), LV_OBJ_FLAG_SCROLLABLE);
            lv_obj_clear_flag(lv_obj_get_parent(lv_obj_get_parent(obj)), LV_OBJ_FLAG_SCROLLABLE);
            printf("page 1 left_val:%d\n", (4 + temp / LV_HOR_RES_MAX));

        }

    }
    else if (code == LV_EVENT_SCROLL_BEGIN)
    {
        //vers_fast_sroll_flag = true;
    }

}


void main_ui0_entry(lv_obj_t* obj)
{

    printf("main_ui0_entry\r\n");
    lv_obj_set_style_pad_all(obj, 0, 0);
    lv_obj_set_style_border_width(obj, 0, 0);
    lv_obj_set_style_bg_color(obj, lv_color_black(), 0);
    lv_obj_set_size(obj, LV_PCT(100), LV_PCT(100));
    lv_obj_set_scrollbar_mode(obj, LV_SCROLLBAR_MODE_OFF);

    //lv_obj_t *img_bg = lv_img_create(parent);
    //lv_img_set_src(img_bg,img_A020);
    lv_obj_t* img_bg = lv_img_create(obj);
    lv_img_set_src(img_bg, "S:img_bin/submenu2_idx0_ico.bin");
    lv_obj_align(img_bg, LV_ALIGN_CENTER, 0, 0);
    
}
void lv_test_view(lv_obj_t* parent)
{
    lv_obj_set_size(parent, LV_PCT(100), LV_PCT(100));
    lv_obj_set_style_pad_all(parent, 0, 0);
    lv_obj_set_style_border_width(parent, 0, 0);
    lv_obj_set_style_bg_color(parent, lv_color_black(), 0);
    lv_obj_t* text1 = lv_label_create(parent);
    lv_obj_t* text2 = lv_label_create(parent);
    lv_label_set_recolor(text1,true);
    lv_label_set_recolor(text2, true);
    lv_label_set_text_fmt(text1, "#ffffff val1 99 #");
    lv_obj_align(text1, LV_ALIGN_TOP_LEFT, 0, 0);
    lv_label_set_text_fmt(text2, "#ffffff val2 199 #");
    lv_obj_align(text2, LV_ALIGN_CENTER, 0, 0);
}

void lv_main_cont(lv_obj_t* obj) // 5个主界面 
{
    if (!lv_obj_is_valid(obj))
        return;

    lv_obj_remove_style_all(obj);
    lv_obj_set_style_pad_all(obj, 0, 0);
    lv_obj_set_style_border_width(obj, 0, 0);
    lv_obj_set_style_bg_color(obj, lv_color_black(), 0);

    lv_obj_set_size(obj, LV_PCT(100), LV_PCT(100));
    lv_obj_set_scroll_snap_x(obj, LV_SCROLL_SNAP_CENTER);//x方向滚动
    //lv_obj_set_scroll_snap_y(main_cont, LV_SCROLL_SNAP_CENTER);
    lv_obj_set_scrollbar_mode(obj, LV_SCROLLBAR_MODE_OFF);
    lv_obj_clear_flag(obj, LV_OBJ_FLAG_SCROLL_ELASTIC);
    lv_obj_add_flag(obj, LV_OBJ_FLAG_SCROLL_MOMENTUM);
    lv_obj_add_flag(obj, LV_OBJ_FLAG_SCROLL_ONE);
    lv_obj_set_scroll_dir(obj, LV_DIR_HOR);
    lv_obj_set_flex_flow(obj, LV_FLEX_FLOW_COLUMN_WRAP);



    lv_obj_add_event_cb(obj, main_cont_cb, LV_EVENT_ALL, obj);

    // lv_obj_t *cont_left_1 = lv_obj_create(obj);
    lv_obj_t* cont_left_1 = lv_obj_create(obj);
    main_ui0_entry(cont_left_1);
#if 0
    if (dsp_get_system_watch_face() == 0) //根据返回的face显示不同的时钟表盘
        main_ui0_entry(cont_left_1);
    else if (dsp_get_system_watch_face() == 1)
        main_ui1_entry(cont_left_1);
    else if (dsp_get_system_watch_face() == 2)
        main_ui1_entry(cont_left_1);
    else if (dsp_get_system_watch_face() == 3)
        main_ui1_entry(cont_left_1);
    else if (dsp_get_system_watch_face() == 4)
        main_ui1_entry(cont_left_1);
#endif

    //lv_obj_t* cont_left_2 = lv_obj_create(obj);
    //lv_sport_menu(cont_left_2);//运动菜单

    //lv_obj_t* cont_left_3 = lv_obj_create(obj);
    //lv_app_heartrate_menu(cont_left_3);//心率界面

    //lv_obj_t* cont_left_4 = lv_obj_create(obj);
    //lv_sleep_menu(cont_left_4);//睡眠界面

    //lv_obj_t* cont_left_5 = lv_obj_create(obj);
    //lv_weather_menu(cont_left_5);//天气界面

    lv_obj_t* cont_left_6 = lv_obj_create(obj);
    lv_test_view(cont_left_6);

}

static void float_cont_cb(lv_event_t* e)
{

    lv_event_code_t code = lv_event_get_code(e);
    lv_obj_t* obj = lv_event_get_target(e);
    lv_obj_t* kb = lv_event_get_user_data(e);

    if (!lv_obj_is_valid(kb))
        return;

    if (code == LV_EVENT_SCROLL_END)
    {
        lv_coord_t temp = lv_obj_get_scroll_top(kb);//获取顶端滚动坐标
        //if (temp == LV_VER_RES_MAX)
        //    dsp_store_ui_scene(0, 1, 0, 0, 0);//设置界面到0 
        //else
        //    dsp_store_ui_scene(0, 1, 1, 0, 0);
        printf("scroll top_val:%d\n", temp);
    }
    else if (code == LV_EVENT_SCROLL_BEGIN)
    {

    }
}

static void float_cont_mid2_cb(lv_event_t* e)
{
    lv_event_code_t code = lv_event_get_code(e);

    lv_obj_t* obj = lv_event_get_target(e);

    if (!lv_obj_is_valid(obj))
        return;

    if (code == LV_EVENT_SCROLL_PREDICT)
    {

        lv_point_t* srcoll_sum = lv_event_get_param(e);

        /*Decide if it's a horizontal or vertical scroll*/
        bool hor_en = false;
        bool ver_en = false;
        if (LV_ABS(srcoll_sum->x) > LV_ABS(srcoll_sum->y))
        {
            hor_en = true;
        }
        else
        {
            ver_en = true;
        }

        if (ver_en)
        {
            if (srcoll_sum->y > 0)
            {
                //lv_obj_clear_flag(lv_obj_get_child(lv_obj_get_parent(lv_obj_get_parent(obj)), 0), LV_OBJ_FLAG_HIDDEN);
            }
        }

        //printf("srcoll_sum->y :%d \n", srcoll_sum->y);
    }
    else if (code == LV_EVENT_SCROLL_END)
    {
        lv_obj_t* kb = lv_event_get_user_data(e);
        if (!lv_obj_is_valid(kb))
            return;
        lv_coord_t temp = lv_obj_get_scroll_top(kb);

        if (temp == 0)
        {
            lv_obj_add_flag(lv_obj_get_parent(obj), LV_OBJ_FLAG_SCROLLABLE);
            lv_obj_add_flag(lv_obj_get_parent(lv_obj_get_parent(obj)), LV_OBJ_FLAG_SCROLLABLE);
            //lv_obj_clear_flag(lv_obj_get_child(lv_obj_get_parent(lv_obj_get_parent(obj)), 0), LV_OBJ_FLAG_HIDDEN);
           // dsp_store_ui_scene(0, 1, 0, 0, 0);
        }
        else if (temp == LV_VER_RES_MAX)
        {
            lv_obj_clear_flag(lv_obj_get_parent(obj), LV_OBJ_FLAG_SCROLLABLE);
            lv_obj_clear_flag(lv_obj_get_parent(lv_obj_get_parent(obj)), LV_OBJ_FLAG_SCROLLABLE);
            //lv_obj_add_flag(lv_obj_get_child(lv_obj_get_parent(lv_obj_get_parent(obj)), 0), LV_OBJ_FLAG_HIDDEN);
            //dsp_store_ui_scene(0, 1, 3, 0, 0);
        }
        printf("float_cont_mid2_cb:top_val:%d\n", temp);

    }
    else if (code == LV_EVENT_SCROLL_BEGIN)
    {
    }
}
typedef struct
{
    uint8_t month;
    uint8_t day;
    uint8_t hour;
    uint8_t minute;
    uint8_t week;
} Date_str;
static lv_obj_t* time_disp_label, * date_disp_label, * battery_label;

void lv_app_mainmenu_up(lv_obj_t* parent)
{

    uint8_t i;
    lv_obj_t* old_obj_btn;
    //init parent
    lv_obj_set_style_pad_all(parent, 0, 0);
    lv_obj_set_style_border_width(parent, 0, 0);
    lv_obj_set_style_bg_color(parent, lv_color_black(), 0);
    lv_obj_set_size(parent, LV_PCT(100), LV_PCT(100));
    lv_obj_set_scrollbar_mode(parent, LV_SCROLLBAR_MODE_OFF);
    //if (dsp_get_system_ble_state() > 3)
    //    lv_label_set_text_fmt(time_disp_label, LV_SYMBOL_BLUETOOTH"  %02d:%02d  %s", dsp_get_system_time_hour(), dsp_get_system_time_minute(), battery_char[i]);
    //else
    //    lv_label_set_text_fmt(time_disp_label, "   %02d:%02d  %s", dsp_get_system_time_hour(), dsp_get_system_time_minute(), battery_char[i]);

    //lv_obj_align(time_disp_label, LV_ALIGN_TOP_LEFT, 60, 200);

    date_disp_label = lv_label_create(parent);
    lv_label_set_recolor(date_disp_label, true);                        /*Enable re-coloring by commands in the text*/
    //lv_label_set_text_fmt(date_disp_label, "#ffffff WOBBLE#");
    lv_label_set_text_fmt(date_disp_label, "#ffffff top %02d/%02d   %s",12, 11, "tru");
    //lv_obj_align_to(date_disp_label, time_disp_label, LV_ALIGN_OUT_BOTTOM_LEFT, 10, 5);
    lv_obj_align(date_disp_label, LV_ALIGN_TOP_LEFT, 60, 200);

}
uint32_t child_id = 0;
void app_msg_list(lv_obj_t* obj)
{
    /*Create a list*/
    //lv_obj_t* list = lv_list_create(obj);
    ////父类list的设置
    ////lv_obj_set_width(list1,240);

    //lv_obj_set_size(list, LV_PCT(100), LV_PCT(100));
    //lv_obj_set_style_bg_color(list, lv_color_black(), _LV_STYLE_STATE_CMP_SAME);
    //lv_obj_set_style_border_color(list, lv_color_black(), _LV_STYLE_STATE_CMP_SAME);
    ////子类中的顶上的间隔
    //lv_obj_set_style_pad_top(list, 8, _LV_STYLE_STATE_CMP_SAME);
    ////子类之间的间隔
    //lv_obj_set_style_pad_gap(list, 8, _LV_STYLE_STATE_CMP_SAME);
    //lv_list_add_btn(list, "S:img_bin/submenu2_idx1_ico.bin", "Weixin message!!");
    //lv_list_add_btn(list, "S:img_bin/submenu2_idx2_ico.bin", "QQ message!!");
    //lv_list_add_btn(list, "S:img_bin/submenu2_idx3_ico.bin", "SMS message!!");
    //lv_list_add_btn(list, "S:img_bin/submenu2_idx4_ico.bin", "Facebook message!!");
    ////lv_list_msg_add_btn(list, img_D076, "Line message!!",event_handler);
    ////lv_list_msg_add_btn(list, img_D077, "Twiter message!!",event_handler);
    ////lv_list_msg_add_btn(list, img_D078, "Sake message!!",event_handler);

    //lv_obj_scroll_to_view(lv_obj_get_child(list, child_id), LV_ANIM_OFF);

   lv_obj_t * disp_label = lv_label_create(obj);
    lv_label_set_recolor(disp_label, true);                        /*Enable re-coloring by commands in the text*/
    //lv_label_set_text_fmt(date_disp_label, "#ffffff WOBBLE#");
    lv_label_set_text_fmt(disp_label, "#ffffff bottom_list");
    //lv_obj_align_to(date_disp_label, time_disp_label, LV_ALIGN_OUT_BOTTOM_LEFT, 10, 5);
    lv_obj_align(disp_label, LV_ALIGN_TOP_LEFT, 60, 200);
}
void lv_float_cont(lv_obj_t* obj)
{

    if (!lv_obj_is_valid(obj))
        return;

    lv_obj_remove_style_all(obj);
    //lv_obj_set_style_pad_all(main_float_cont, 0, 0);
    //lv_obj_set_style_border_width(main_float_cont, 0, 0);
    lv_obj_set_size(obj, LV_PCT(100), LV_PCT(100));
    //lv_obj_set_scroll_snap_x(main_float_cont, LV_SCROLL_SNAP_CENTER);
    lv_obj_set_scroll_snap_y(obj, LV_SCROLL_SNAP_CENTER);//设置y方向滚动
    lv_obj_set_scrollbar_mode(obj, LV_SCROLLBAR_MODE_OFF);
    lv_obj_clear_flag(obj, LV_OBJ_FLAG_SCROLL_ELASTIC);
    lv_obj_add_flag(obj, LV_OBJ_FLAG_SCROLL_MOMENTUM);
    lv_obj_add_flag(obj, LV_OBJ_FLAG_SCROLL_ONE);
    lv_obj_set_scroll_dir(obj, LV_DIR_VER);//LV_DIR_TOP | LV_DIR_BOTTOM,
    lv_obj_set_flex_flow(obj, LV_FLEX_FLOW_ROW_WRAP);
    lv_obj_add_event_cb(obj, float_cont_cb, LV_EVENT_ALL, obj);

    lv_obj_t* float_cont_top = lv_obj_create(obj);//创建顶端下拉菜单对象
    lv_app_mainmenu_up(float_cont_top);//实例化顶端下拉菜单对象

    lv_obj_t* float_cont_right = lv_obj_create(obj);

    lv_obj_remove_style_all(float_cont_right);
    lv_obj_set_size(float_cont_right, LV_PCT(100), LV_PCT(100));
    //lv_obj_set_scroll_snap_x(float_cont_right, LV_SCROLL_SNAP_START);
    lv_obj_set_scroll_snap_y(float_cont_right, LV_SCROLL_SNAP_CENTER);
    lv_obj_set_scrollbar_mode(float_cont_right, LV_SCROLLBAR_MODE_OFF);
    lv_obj_clear_flag(float_cont_right, LV_OBJ_FLAG_SCROLL_ELASTIC);
    lv_obj_add_flag(float_cont_right, LV_OBJ_FLAG_SCROLL_MOMENTUM);
    lv_obj_add_flag(float_cont_right, LV_OBJ_FLAG_SCROLL_ONE);
    lv_obj_set_flex_flow(float_cont_right, LV_FLEX_FLOW_ROW_WRAP);
    lv_obj_set_scroll_dir(float_cont_right, LV_DIR_VER);
    lv_obj_add_event_cb(float_cont_right, float_cont_mid2_cb, LV_EVENT_ALL, float_cont_right);

    lv_obj_t* float_cont_mid2 = lv_obj_create(float_cont_right);//公共浮动对象
    lv_obj_remove_style_all(float_cont_mid2);
    lv_obj_set_size(float_cont_mid2, LV_PCT(100), LV_PCT(100));

    lv_obj_t* float_cont_bottom = lv_obj_create(float_cont_right);//创建消息list的父对象
    lv_obj_set_style_pad_all(float_cont_bottom, 0, 0);
    lv_obj_set_style_border_width(float_cont_bottom, 0, 0);
    lv_obj_set_style_bg_color(float_cont_bottom, lv_color_black(), 0);

    lv_obj_set_size(float_cont_bottom, LV_PCT(100), LV_PCT(100));
    lv_obj_set_scrollbar_mode(float_cont_bottom, LV_SCROLLBAR_MODE_OFF);
    app_msg_list(float_cont_bottom);//加载消息list界面


    lv_obj_t* float_cont_mid = lv_obj_create(float_cont_mid2);//创建中间主界面的对象
    lv_main_cont(float_cont_mid);

    lv_obj_scroll_to(obj, 0, 0, LV_ANIM_OFF);
//#if 1
//    //printf("sync_cm3_data.ui_info.layer1.ui_page_id :%d \n",sync_cm3_data.ui_info.layer1.ui_page_id);
//
//    //lv_obj_scroll_by(float_cont_mid, -LV_HOR_RES_MAX / 2, 0, LV_ANIM_OFF);
//    lv_obj_scroll_by(obj, 0, -LV_VER_RES_MAX, LV_ANIM_OFF);
//
//    if (dsp_get_ui_scene_page_by_layer(1) == 1)
//    {
//        printf("11111\n");
//        lv_obj_scroll_to(obj, 0, 0, LV_ANIM_OFF);
//    }
//#if 0
//    else if (dsp_get_ui_scene_page_by_layer(1) == 2)
//    {
//        lv_obj_scroll_to(float_cont_mid, 0, 0, LV_ANIM_OFF);
//        lv_obj_clear_flag(lv_obj_get_parent(float_cont_mid), LV_OBJ_FLAG_SCROLLABLE);
//        lv_obj_clear_flag(lv_obj_get_child(float_cont_mid, 1), LV_OBJ_FLAG_SCROLLABLE);
//    }
//#endif
//    else if (dsp_get_ui_scene_page_by_layer(1) == 3)
//    {
//        printf("333333\n");
//        lv_obj_scroll_to(float_cont_right, 0, LV_VER_RES_MAX, LV_ANIM_OFF);
//        lv_obj_clear_flag(lv_obj_get_parent(float_cont_right), LV_OBJ_FLAG_SCROLLABLE);
//        //lv_obj_clear_flag(lv_obj_get_parent(lv_obj_get_parent(float_cont_right)), LV_OBJ_FLAG_SCROLLABLE);
//        //lv_obj_add_flag(lv_obj_get_child(lv_obj_get_parent(lv_obj_get_parent(float_cont_right)), 0), LV_OBJ_FLAG_HIDDEN);
//    }
//#else
//    lv_obj_scroll_by(float_cont_mid, -LV_HOR_RES_MAX / 2, 0, LV_ANIM_OFF);
//    lv_obj_scroll_by(obj, 0, -LV_VER_RES_MAX, LV_ANIM_OFF);
//#endif
}

//frame 2:layer
static void return_main_timer_cb(lv_timer_t* t)
{
    lv_obj_t* obj = t->user_data;

    lv_timer_del(t);

    if (!lv_obj_is_valid(obj))
        return;

    lv_obj_clean(obj);
    prj_prev_cont = lv_obj_create(obj);
    ui_main_float(prj_prev_cont);


}

#if 1

ui_entry cont_backup;
static void layer_main_cb(lv_event_t* e)
{
    lv_event_code_t code = lv_event_get_code(e);
    lv_obj_t* obj = lv_event_get_target(e);

    if (!lv_obj_is_valid(obj))
        return;

    if (code == LV_EVENT_SCROLL_END)
    {
        lv_obj_t* kb = lv_event_get_user_data(e);
        lv_coord_t temp = lv_obj_get_scroll_left(kb);
        // printf("lv_obj_get_scroll_left :%d \n", temp);
        if (temp == 0)
        {
            //===============
            //if (cont_backup == lv_app_system_setting)
            //{
            //    lv_obj_clean(prj_parent_cont);
            //    prj_prev_cont = lv_obj_create(prj_parent_cont);
            //   //layer_main_cont(prj_prev_cont, lv_app_mainmenu_up, lv_app_system_setting);
            //}
            //else
            //    //===============
            //{
            //    lv_obj_clean(prj_parent_cont);
            //    prj_prev_cont = lv_obj_create(prj_parent_cont);
            //    //lv_app_mainmenu_up(prj_prev_cont);
            //    lv_timer_create(return_main_timer_cb, 2, prj_parent_cont);
            //}
        }
    }
}

void layer_main_cont(lv_obj_t* parent, ui_entry f_cont, ui_entry f_cont1)
{

    //init parent
    lv_obj_t* obj = parent;
    lv_obj_set_style_pad_all(obj, 0, 0);
    lv_obj_set_style_border_width(obj, 0, 0);
    lv_obj_set_style_border_side(obj, 0, 0);
    lv_obj_set_style_bg_color(obj, lv_color_black(), 0);
    lv_obj_set_size(obj, LV_PCT(100), LV_PCT(100));
    lv_obj_set_scroll_snap_x(obj, LV_SCROLL_SNAP_CENTER);
    lv_obj_set_scrollbar_mode(obj, LV_SCROLLBAR_MODE_OFF);
    //lv_obj_clear_flag(obj, LV_OBJ_FLAG_SCROLL_ELASTIC);
    //lv_obj_add_flag(obj, LV_OBJ_FLAG_SCROLL_MOMENTUM);
    //lv_obj_add_flag(obj, LV_OBJ_FLAG_SCROLL_ONE);
    lv_obj_set_scroll_dir(obj, LV_DIR_HOR);
    //lv_obj_set_flex_flow(obj, LV_FLEX_FLOW_COLUMN_WRAP);
    //lv_obj_set_style_pad_column(obj, 0, 0);
    lv_obj_add_event_cb(obj, layer_main_cb, LV_EVENT_ALL, obj);


    lv_obj_t* cont = lv_obj_create(obj);
    lv_obj_update_layout(cont);  /*Be sure the size is correct*/
    lv_obj_set_pos(cont, 0 * lv_obj_get_content_width(obj), 0 * lv_obj_get_content_height(obj));
    //--------------
    cont_backup = f_cont;//备份上一个界面
    //--------------
    f_cont(cont);

    lv_obj_t* cont1 = lv_obj_create(obj);
    lv_obj_update_layout(cont1);  /*Be sure the size is correct*/
    lv_obj_set_pos(cont1, 1 * lv_obj_get_content_width(obj), 0 * lv_obj_get_content_height(obj));
    f_cont1(cont1);

    // lv_obj_scroll_by(obj, -LV_HOR_RES_MAX, 0, LV_ANIM_ON);
    lv_obj_scroll_by(obj, -LV_HOR_RES_MAX, 0, LV_ANIM_OFF);

}

void layer_left_cb(lv_event_t* e)
{
    lv_event_code_t code = lv_event_get_code(e);
    lv_obj_t* obj = lv_event_get_target(e);
    if (code == LV_EVENT_SCROLL_END)
    {
        lv_obj_t* kb = lv_event_get_user_data(e);
        lv_coord_t temp = lv_obj_get_scroll_left(kb);
        if (temp == 0)
        {
            lv_obj_clean(prj_parent_cont);
            prj_prev_cont = lv_obj_create(prj_parent_cont);
            //sync_cm3_data.ui_info.layer1.ui_page_id = 0;
            //sync_cm3_data.ui_info.layer1.ui_page_cur_x = 0;
            //sync_cm3_data.ui_info.layer1.ui_page_cur_y = 0;
            cont_backup(prj_prev_cont);
            lv_timer_create(return_main_timer_cb, 50, prj_parent_cont);
        }
    }
    else if (code == LV_EVENT_SCROLL_BEGIN)
    {
    }
}

void layer_left_cont(lv_obj_t* parent, ui_entry f_cont, ui_entry f_cont1)
{
    lv_obj_t* obj = parent;
    lv_obj_set_style_pad_all(obj, 0, 0);
    lv_obj_set_style_border_width(obj, 0, 0);
    lv_obj_set_style_border_side(obj, 0, 0);
    lv_obj_set_style_bg_color(obj, lv_color_black(), 0);
    lv_obj_set_size(obj, LV_PCT(100), LV_PCT(100));
    lv_obj_set_scroll_snap_x(obj, LV_SCROLL_SNAP_CENTER);
    lv_obj_set_scrollbar_mode(obj, LV_SCROLLBAR_MODE_OFF);
    lv_obj_clear_flag(obj, LV_OBJ_FLAG_SCROLL_ELASTIC);
    lv_obj_add_flag(obj, LV_OBJ_FLAG_SCROLL_MOMENTUM);
    lv_obj_add_flag(obj, LV_OBJ_FLAG_SCROLL_ONE);
    lv_obj_set_scroll_dir(obj, LV_DIR_HOR);
    lv_obj_set_flex_flow(obj, LV_FLEX_FLOW_COLUMN_WRAP);
    lv_obj_set_style_pad_column(obj, 0, 0);
    lv_obj_add_event_cb(obj, layer_left_cb, LV_EVENT_ALL, obj);
    lv_obj_t* cont = lv_obj_create(obj);
    f_cont(cont);
    lv_obj_t* cont1 = lv_obj_create(obj);
    f_cont1(cont1);
    lv_obj_scroll_by(obj, -LV_HOR_RES_MAX, 0, LV_ANIM_OFF);
}
#endif






